package great.project.easyexcel.easyexcel.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *
 *
 *  </div>
 *
 * @author zhangshun
 * @date 2020/12/2 13:37
 */
@Configuration
public class RedisExcelConfig {

    /**
     * excel 导入信息时 使用的线程池
     *
     * @return 线程池
     */
    @Bean("excelExecutorService")
    public ExecutorService executorService() {
        LinkedBlockingDeque<Runnable> linkedBlockingDeque = new LinkedBlockingDeque<>();
        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setUncaughtExceptionHandler((t, e) -> e.printStackTrace())
                .setNameFormat("excel-pool-%d").build();
        return new ThreadPoolExecutor(
                20,
                25,
                10000,
                TimeUnit.SECONDS,
                linkedBlockingDeque,
                namedThreadFactory,
                new ThreadPoolExecutor.DiscardPolicy());
    }
}